package arduino;

import java.io.IOException;

import net.udp.server.UDPServer;

public class UDPArduinoServer extends UDPServer {

	private AServer aserver;
	public UDPArduinoServer() throws InstantiationException,
			IllegalAccessException, ClassNotFoundException {
		super();
		
		aserver =  AServer.getInstance();	
		System.out.println("Initializing....");
		
		while(!aserver.isReady())
		{
			try {Thread.sleep(500);} catch (InterruptedException ie) {}
		}
		
		System.out.println("Arduino is ready! ");
		run();
	}
	@Override
	public String process(String string) throws IOException {
		
		aserver.sendMessage(AProtocol.parse(string));
		String output = aserver.outputLine;
		return output;
	}
	
	
	
	public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
		UDPArduinoServer s = new UDPArduinoServer();
		
		
//		AProtocol a = new AProtocol();
//		a.in_angle=120;
//		a.in_vel=128;
//		a.in_direction=1;
//		a.in_beep_hz=255;
//		a.in_beep_msec=1000;
//		
//		s.process(a.toString());
//		
//		try {Thread.sleep(1500);} catch (InterruptedException ie) {}
//		a.in_angle=60;
//		a.in_vel=0;
//		a.in_direction=0;
//		a.in_beep_msec=0;
//		s.process(a.toString());
	}
	
	
	

}
